// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class DataframeEvaluationRegression
{
	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("actual_field")]
	public Elastic.Clients.Elasticsearch.Field ActualField { get; set; }

	/// <summary>
	/// <para>
	/// Specifies the metrics that are used for the evaluation. For more information on mse, msle, and huber, consult the Jupyter notebook on regression loss functions.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("metrics")]
	public Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetrics? Metrics { get; set; }

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("predicted_field")]
	public Elastic.Clients.Elasticsearch.Field PredictedField { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation(DataframeEvaluationRegression dataframeEvaluationRegression) => Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation.Regression(dataframeEvaluationRegression);
}

public sealed partial class DataframeEvaluationRegressionDescriptor<TDocument> : SerializableDescriptor<DataframeEvaluationRegressionDescriptor<TDocument>>
{
	internal DataframeEvaluationRegressionDescriptor(Action<DataframeEvaluationRegressionDescriptor<TDocument>> configure) => configure.Invoke(this);

	public DataframeEvaluationRegressionDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Field ActualFieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetrics? MetricsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor MetricsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor> MetricsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Field PredictedFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> ActualField(Elastic.Clients.Elasticsearch.Field actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> ActualField<TValue>(Expression<Func<TDocument, TValue>> actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> ActualField(Expression<Func<TDocument, object>> actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the metrics that are used for the evaluation. For more information on mse, msle, and huber, consult the Jupyter notebook on regression loss functions.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> Metrics(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetrics? metrics)
	{
		MetricsDescriptor = null;
		MetricsDescriptorAction = null;
		MetricsValue = metrics;
		return Self;
	}

	public DataframeEvaluationRegressionDescriptor<TDocument> Metrics(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor descriptor)
	{
		MetricsValue = null;
		MetricsDescriptorAction = null;
		MetricsDescriptor = descriptor;
		return Self;
	}

	public DataframeEvaluationRegressionDescriptor<TDocument> Metrics(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor> configure)
	{
		MetricsValue = null;
		MetricsDescriptor = null;
		MetricsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> PredictedField(Elastic.Clients.Elasticsearch.Field predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> PredictedField<TValue>(Expression<Func<TDocument, TValue>> predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor<TDocument> PredictedField(Expression<Func<TDocument, object>> predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("actual_field");
		JsonSerializer.Serialize(writer, ActualFieldValue, options);
		if (MetricsDescriptor is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, MetricsDescriptor, options);
		}
		else if (MetricsDescriptorAction is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor(MetricsDescriptorAction), options);
		}
		else if (MetricsValue is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, MetricsValue, options);
		}

		writer.WritePropertyName("predicted_field");
		JsonSerializer.Serialize(writer, PredictedFieldValue, options);
		writer.WriteEndObject();
	}
}

public sealed partial class DataframeEvaluationRegressionDescriptor : SerializableDescriptor<DataframeEvaluationRegressionDescriptor>
{
	internal DataframeEvaluationRegressionDescriptor(Action<DataframeEvaluationRegressionDescriptor> configure) => configure.Invoke(this);

	public DataframeEvaluationRegressionDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Field ActualFieldValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetrics? MetricsValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor MetricsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor> MetricsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Field PredictedFieldValue { get; set; }

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor ActualField(Elastic.Clients.Elasticsearch.Field actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor ActualField<TDocument, TValue>(Expression<Func<TDocument, TValue>> actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field of the index which contains the ground truth. The data type of this field must be numerical.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor ActualField<TDocument>(Expression<Func<TDocument, object>> actualField)
	{
		ActualFieldValue = actualField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Specifies the metrics that are used for the evaluation. For more information on mse, msle, and huber, consult the Jupyter notebook on regression loss functions.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor Metrics(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetrics? metrics)
	{
		MetricsDescriptor = null;
		MetricsDescriptorAction = null;
		MetricsValue = metrics;
		return Self;
	}

	public DataframeEvaluationRegressionDescriptor Metrics(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor descriptor)
	{
		MetricsValue = null;
		MetricsDescriptorAction = null;
		MetricsDescriptor = descriptor;
		return Self;
	}

	public DataframeEvaluationRegressionDescriptor Metrics(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor> configure)
	{
		MetricsValue = null;
		MetricsDescriptor = null;
		MetricsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor PredictedField(Elastic.Clients.Elasticsearch.Field predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor PredictedField<TDocument, TValue>(Expression<Func<TDocument, TValue>> predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The field in the index that contains the predicted value, in other words the results of the regression analysis.
	/// </para>
	/// </summary>
	public DataframeEvaluationRegressionDescriptor PredictedField<TDocument>(Expression<Func<TDocument, object>> predictedField)
	{
		PredictedFieldValue = predictedField;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		writer.WritePropertyName("actual_field");
		JsonSerializer.Serialize(writer, ActualFieldValue, options);
		if (MetricsDescriptor is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, MetricsDescriptor, options);
		}
		else if (MetricsDescriptorAction is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationRegressionMetricsDescriptor(MetricsDescriptorAction), options);
		}
		else if (MetricsValue is not null)
		{
			writer.WritePropertyName("metrics");
			JsonSerializer.Serialize(writer, MetricsValue, options);
		}

		writer.WritePropertyName("predicted_field");
		JsonSerializer.Serialize(writer, PredictedFieldValue, options);
		writer.WriteEndObject();
	}
}